<?php
namespace app\admin\model;

use think\Model;

class Goods extends Base
{
    protected $name = 'goods';

    // 开启自动补齐时间戳
    protected $autoWriteTimestamp = true;

    //定义自动完成的时间戳的实际字段
    protected $createTime = 'create_time';
    protected $updateTime = false;

    // 上架||下架
    public function setIsStatus($id){
        $info = $this->getFind(['id' => $id])['data'];

        if($info['status'] == 0){
            $isshow       = 1;
            $back['flag'] = 1;
            $back['msg']  = '上架成功';
        }else{
            $isshow       = 0;
            $back['flag'] = 0;
            $back['msg']  = '下架成功';
        }

        $data = [
            'id'      => $id,
            'status'  => $isshow,
        ];
        
        $this->update($data);
        return $back;
    }

    public function getCateIdAttr($val){
        if($val == 0){
            return '-';
        }

        return (new Cate())->getVal(['id' => $val], 'name')['data'];
    }

    public function getTypeAttr($val){
        $type = [1 => '实物', 2 => '积分', 3 => '次卡', 4 => '福利卡'];
        return $type[$val];
    }
}